<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8">
    <meta name="csrf-token" content="{{ csrf_token() }}"/>
    <title>
        {% block title %}
        {{ BlogInfo.query.first().title }}
        {% endblock %}
    </title>
    {% block stylesheet %}
        <link href="{{ url_for('static', filename='css/bootstrap.css') }}" rel="stylesheet">
        <link href="{{ url_for('static', filename='css/common.css') }}" rel="stylesheet">
    {% endblock %}
</head>
<body>
<header>
    <div class='header-top'>
        <div class="container">
            <h2  class="blog-title"><a href="{{ url_for('main.index') }}">{{ BlogInfo.query.first().title }}</a></h2>
            <p class="lead signature">
                {{ BlogInfo.query.first().signature }}
            </p>
        </div>
    </div>
    <nav class="navbar navbar-{{ BlogInfo.query.first().navbar }}" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">切换导航</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class=""><a href="/"><span class="glyphicon glyphicon-home"> 首页</span></a></li>
                    {% for menu in Menu.query.order_by(Menu.order.asc()).all() %}
                        {% if menu.types.count() %}
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ menu.name }} <b
                                        class="caret"></b></a>
                                <ul class="dropdown-menu">
                                    {% for article_type in menu.types.all() %}
                                        {% if not article_type.is_hide %}
                                            <li>
                                                <a href="{{ url_for('main.articleTypes', id=article_type.id) }}">
                                                    {{ article_type.name }}
                                                </a>
                                            </li>
                                            <li class="divider"></li>
                                        {% endif %}
                                    {% endfor %}
                                </ul>
                            </li>
                        {% endif %}
                    {% endfor %}
                    {% for article_type in ArticleType.query.all() %}
                        {% if not article_type.menu %}
                            {% if not article_type.is_hide %}
                                <li>
                                    <a href="{{ url_for('main.articleTypes', id=article_type.id) }}">
                                        {{ article_type.name }}
                                    </a>
                                </li>
                            {% endif %}
                        {% endif %}
                    {% endfor %}
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    {% if current_user.is_authenticated %}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <img src="{{ current_user.gravatar(size=18) }}">
                                {{ current_user.username }} <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="{{ url_for('admin.submitArticles') }}">发表博文</a></li>
                                <li><a href="{{ url_for('admin.account') }}">管理博客</a></li>
                                <li><a href="{{ url_for('auth.logout') }}">退出登陆</a></li>
                            </ul>
                        </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>
</header>
{% block Content %}
    <div class="content">
        <div class="container">
            <div class="row">
                <div class="col-md-8 article">
                    {% for category, message in get_flashed_messages(with_categories=true) %}
                        <div class="alert alert-{{ category }} alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            {{ message }}
                        </div>
                    {% endfor %}
                    {% block content %}
                    {% endblock %}
                </div>
                <div class="col-md-4 blog_nav">
                    {% block blog_nav_plugin %}
                        {% for plugin in Plugin.query.order_by(Plugin.order.asc()).all() %}
                            {% if plugin.disabled != True %}
                                {% if plugin.content != 'system_plugin' %}
                                    <div id="{{ plugin.title }}" class="entry-box">
                                        <h5><strong>{{ plugin.title }}</strong></h5>
                                        {{ plugin.content | safe }}
                                    </div>
                                {% else %}
                                    <div class="entry-box">
                                        <h5><strong>博客统计</strong></h5>
                                        <p>访问量：<span class="badge">{{ BlogView.query.first().num_of_view }}</span></p>
                                        <p>
                                            博文总数：<span class="badge">{{ Article.query.count() }}</span>
                                            评论总数：<span class="badge">{{ Comment.query.count() }}</span>
                                        </p>
                                        <p>
                                            {% for source in Source.query.all() %}
                                                <a href="{{ url_for('main.article_sources', id=source.id) }}">{{ source.name }}</a>：
                                                <span class="badge">{{ source.articles.count() }}</span>
                                            {% endfor %}
                                        </p>
                                    </div>
                                {% endif %}
                            {% endif %}
                        {% endfor %}
                    {% endblock %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
<div class="footer">
    <p class="footer-content">
        @2016
        <a href="#">Blog_mini</a>
        -开源博客系统
        {% if not current_user.is_authenticated %}
            -<a href="{{ url_for('auth.login') }}">
            <span class="glyphicon glyphicon-wrench">后台管理</span>
        </a>
        {% endif %}
    </p>
</div>
<div class="btn-group-vertical floatButton">
    <button id="goTop" class="btn btn-default" title="去顶部" type="button">
        <span class="glyphicon glyphicon-arrow-up"></span>
    </button>
    <button id="refresh" class="btn btn-default" title="刷新" type="button">
        <span class="glyphicon glyphicon-refresh"></span>
    </button>
    <button id="goBottom" class="btn btn-default" title="去底部" type="button">
        <span class="glyphicon glyphicon-arrow-down"></span>
    </button>
</div>
{% block script %}
    <script src="{{ url_for('static', filename='js/jquery-2.2.1.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/floatButton.js') }}"></script>
    {# csrfToken for Ajax   #}
    <script>
        var csrfToken = $('meta[name="csrf-token"]').attr('content');
        $.ajaxSetup({
            beforeSend: function (xhr, settings) {
                if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type)) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken)
                }
            }
        })
    </script>
    {{ moment.include_moment() }}
    {{ moment.lang('zh-cn') }}
{% endblock %}
</body>
</html>
